package OSMS.action.Boss;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import OSMS.dao.BossDao;
import OSMS.dao.GoodsDao;
import OSMS.entity.Boss;
import OSMS.entity.Goods;

public class ShowTypesServlet extends HttpServlet {
	BossDao bdao = new BossDao();
	GoodsDao gdao = new GoodsDao();
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		//从session中获取当前登录商家的bid 所以只能查找该商家旗下所有商品的订单
		HttpSession session = request.getSession();
		Object obj_user = session.getAttribute("boss");
		Boss boss = (Boss) obj_user;
		int bid ;
		Object id1 = boss.getBid();
		bid = (int)id1;
		//获取goodslist.jsp传来的gid
		String tid = request.getParameter("tid");
		try {
			//调用dao的方法查询商品数据
			ArrayList<Goods> goodsList = (ArrayList<Goods>)gdao.searchGoodsByBidAndTid(bid, tid);
			//将数据装入域对象中
			request.setAttribute("goodsList", goodsList);
			//将查询结果跳转到seartchgoods.jsp页面中展示
			request.setCharacterEncoding("utf-8");
			
			request.getRequestDispatcher("../boss/index.jsp").forward(request, response);
		}catch(Exception e) {
			e.printStackTrace();
		}
		
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}
	
}
